﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdonetText
{
    class Program
    {
        static void Main(string[] args)
        {
            string ConString = "server=.;database=Admin;uid=sa;pwd=123456;";

            SqlConnection sql = new SqlConnection(ConString);

            //获取数据库信息
            //SqlCommand sqlCommand = new SqlCommand("select *from Student", sql);


            //增加一条数据
            var insertString =string.Format("insert into Student(name,sex) values('{0}','{1}')","Bob","男");

            //修改数据
            var UpdateString ="update Student set sex='女' where id = 2";


            sql.Open();//打开数据库

            //删除数据
            var DeleteString = "Delete from Student where id=5;";

            SqlCommand com = new SqlCommand(DeleteString, sql);

            var res = com.ExecuteNonQuery();
            Console.WriteLine(res);

            
            //读取数据库
            //var reader = sqlCommand.ExecuteReader();

            //while (reader.Read())
            //{
            //    Console.WriteLine(
            //        "{0}\t{1}\t{2}\t{3}\t{4}\t",
            //       reader["id"], reader["name"], reader["sex"], reader["CreatedTime"], reader["UpdatedTime"]);
            //}



            sql.Close();//关闭数据库

        }
    }
}
